package com.gxa.employment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.employment.entity.pojo.Employment;
import com.gxa.employment.entity.pojo.Student;
import com.gxa.employment.mapper.EmploymentMapper;
import com.gxa.employment.service.EmploymentService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 学生就业信息表 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-03-25
 */
@Service
public class EmploymentServiceImpl extends ServiceImpl<EmploymentMapper, Employment> implements EmploymentService {
    private final StudentServiceImpl studentServiceImpl;

    public EmploymentServiceImpl(StudentServiceImpl studentServiceImpl) {
        this.studentServiceImpl = studentServiceImpl;
    }

    //    增
    @Transactional(rollbackFor = Throwable.class)
    @Override
    public void addEmp(Employment emp) {
        LambdaQueryWrapper<Employment> queryWrapper = new LambdaQueryWrapper<>(Employment.class);
       queryWrapper.eq(Employment::getEmpId, emp.getEmpId())
                .eq(Employment::getEntId,emp.getEntId())
               .eq(Employment::getJobId, emp.getJobId());
        Employment getOne = getOne(queryWrapper);
        if (getOne != null) {
            throw new RuntimeException("该学生已存在就业信息");
        }
        save(emp);
        Student byId = studentServiceImpl.getById(emp.getStuId());
        byId.setStuStatus("就业");
        studentServiceImpl.updateById(byId);
    }

}
